package org.dstart.air.window.sub.draw
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.geom.Matrix;

	public class DrawBackground extends Sprite
	{
		private var m_lineColor:uint;		//	外框填充颜色
		private var m_fillColor:uint;		//	内部框填充颜色
		private var m_changeColor:uint;		//	渐变时的填充颜色
		
		private var sprTitle:Sprite;		//	楠题部份
		private var sprMain:Sprite;			//	主场景部份
		
		private var objWidth:Number;
		private var objHeight:Number;
		
		public function DrawBackground(	lineColor:uint = 0x000000, 
										fillColor:uint = 0xFFFFFF, 
										changeColor:uint = 0xF0F0F0)
		{	
			this.m_lineColor = lineColor;
			this.m_fillColor = fillColor;
			this.m_changeColor = changeColor;
			
			objWidth = 100;
			objHeight = 100;
			
			sprTitle = new Sprite();
			sprMain = new Sprite();
			
			addChild(sprMain);
			addChild(sprTitle);
			
			ChangeSize();		
		}
		
		public override function set width(value:Number):void
		{
			objWidth = value;
			
			ChangeSize();
		}
		
		public override function get width():Number
		{
			return objWidth;
		}
		
		public override function set height(value:Number):void
		{
			objHeight = value;
			
			ChangeSize();
		}
		
		public override function get height():Number
		{
			return objHeight;
		}
		
		private function ChangeSize():void
		{
			sprMain.graphics.endFill();
			
			sprMain.graphics.beginFill(this.m_lineColor, 1);
			sprMain.graphics.drawRect(0, 0, objWidth, objHeight);
			sprMain.graphics.endFill();
			
			sprMain.graphics.beginFill(this.m_fillColor, 1);
			sprMain.graphics.drawRect(3, 3, objWidth - 6, objHeight - 6);
			sprMain.graphics.endFill();
			
			var cArray:Array = new Array(this.m_fillColor, this.m_changeColor);
			var aArray:Array = new Array(0xFF, 0xFF);
			var rArray:Array = new Array(0x1F, 0xFF);
			var m:Matrix = new Matrix();
			m.createGradientBox(objWidth - 6, 26, Math.PI/2);
			
			sprTitle.graphics.clear();
			
			sprTitle.graphics.beginFill(this.m_lineColor, 1);
			sprTitle.graphics.drawRect(0, 0, objWidth, 26);
			sprTitle.graphics.endFill();
			
			sprTitle.graphics.beginGradientFill(GradientType.LINEAR, cArray, aArray, rArray, m);
			sprTitle.graphics.drawRect(3, 3, objWidth - 6, 22);
			sprTitle.graphics.endFill();
		}
	}
}